//
//  ViewController.m
//  29-HomeWork
//
//  Created by 鹏飞罗 on 16/8/23.
//  Copyright © 2016年 罗鹏飞. All rights reserved.
//

#import "ViewController.h"

#import "PushView.h"
#import "PopView.h"
#import "SecondViewController.h"
#define kTableViewCell @"reuse"

@interface ViewController ()<UITableViewDelegate,UITableViewDataSource,UINavigationControllerDelegate>
@property (nonatomic, strong) UITableView *myTableView;
@property (nonatomic, strong) NSMutableArray *picArray;
@property (nonatomic, strong) NSMutableArray *textArray;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _picArray = [NSMutableArray array];
    _textArray = [NSMutableArray array];
    [self handData];
    // Do any additional setup after loading the view, typically from a nib.
    self.myTableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    self.myTableView.delegate = self;
    self.myTableView.dataSource = self;
    self.navigationController.delegate = self;
    [self.view addSubview:_myTableView];
    [self.myTableView registerNib:[UINib nibWithNibName:@"MyTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:kTableViewCell];
}
- (nullable id <UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController
                                            animationControllerForOperation:(UINavigationControllerOperation)operation
                                                         fromViewController:(UIViewController *)fromVC
                                                           toViewController:(UIViewController *)toVC {
    if (operation == UINavigationControllerOperationPush) {
        PushView *push = [[PushView alloc] init];
        return push;
    } else if (operation == UINavigationControllerOperationPop) {
        PopView *pop = [[PopView alloc] init];
        return pop;
    } else {
        
    }
    return nil;
}
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    self.cell = [tableView cellForRowAtIndexPath:indexPath];
    SecondViewController *secondVC = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:[NSBundle mainBundle]];
    secondVC.imageName = _picArray[indexPath.row];
    secondVC.labelText = _textArray[indexPath.row];
    
    [self.navigationController pushViewController:secondVC animated:YES];
}


- (void)handData {
    for (int i = 1; i <= 4; i++) {
        [_picArray addObject:[NSString stringWithFormat:@"newsPic%d",i]];
        [_textArray addObject:[NSString stringWithFormat:@"43岁的教授茆长暄这次彻底与自己所供职的学校——上海财经大学闹掰了。这个在2010年被上财从美国引进回来的青年教授被校方告知，在2016年8月31日“常任轨”教授6年聘用期满后，不再续约尴尬的是，9名跟着他进行硕博连读的学生，有的已经拿到硕士文凭，正处于攻读博士的关键期；有的刚刚入学一年，啥情况还不知道，就换了导师。如今，事件正朝着茆长暄和学生们难以控制的方向发展。一方面，自认为学术水平很高、教学水平很高、论文被引用率NO.1的茆长暄多次向学校索要解聘自己的具体理由，却无果；另一方面，9个学生因为没有同领域导师指导，担心自己将来毕不了业。%d",i]];
    }
}
- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return self.view.frame.size.height / 4;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _picArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    _cell = [tableView dequeueReusableCellWithIdentifier:kTableViewCell];
    _cell.myImageView.image = [UIImage imageNamed:_picArray[indexPath.row]];
    return _cell;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
